<?php
/**
 * 简单导出类.
 * 
 * @author  莫 念 
 * @version 1.0
 * @package main
 */


class Exprot{
	protected $config = array();
	 /**
     * 初始化
     * @param type $options 参数
     * @return 
     */
    public  function __construct($options = array()) {
		if(is_array($options)){
			$this->config   =   array_merge($this->config, $options);
		}
		$type = $this->config['type'];
        //导出方案
		$classFile = dirname(__FILE__).'/Driver/Exprot/Exprot'.ucwords(strtolower($type)).'.class.php';
		$class = 'Exprot'.ucwords(strtolower($type));
		if(file_exists($classFile)){
			require_once($classFile);
		}else{
			throw new Exception("导出驱动 {$class} 不存在！");
		}
		if(class_exists($class)){
            $this->connect = new $class($this->config);
        } else {
			throw new Exception("未发现导出驱动 {$class}类！");
        }
    }

	public function downloadHeader($filename, $mimetype, $length = 0, $no_cache = true){
	
		if ($no_cache) {
			$this->noCacheHeader();
		}
		$filename = str_replace(array(';', '"', "\n", "\r"), '-', $filename);
		if (!empty($filename)) {
			header('Content-Description: File Transfer');
			header('Content-Disposition: attachment; filename="' . $filename . $this->connect->ext.'"');
		}
		header('Content-Type: ' . $this->connect->mimetype);
		if (strpos($this->connect->mimetype, 'gzip') !== false) {
			header('Content-Encoding: gzip');
		}
		header('Content-Transfer-Encoding: binary');
		if ($length > 0) {
			header('Content-Length: ' . $length);
		}
	}

	public function noCacheHeader(){
		if (defined('TESTSUITE') && ! defined('PMA_TEST_HEADERS')) {
			return;
		}
		header('Expires: ' . date(DATE_RFC1123));
		
		header(
			'Cache-Control: no-store, no-cache, must-revalidate,'
			. '  pre-check=0, post-check=0, max-age=0'
		);
		//if (PMA_USR_BROWSER_AGENT == 'IE') {
		//	header('Pragma: public');
		//	return;
		//}
		header('Pragma: no-cache'); 
		header('Last-Modified: ' . date(DATE_RFC1123));
	}

	public function exprotHead($head = array()){
		 $this->connect->exprotHead($head);
	}

	public function exprotData($data = array()){

		 $this->connect->exprotData($data);
	}

	
	public function exprotFoot(){
		 $this->connect->exprotFoot();
	}
}
